package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SemealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags ="套餐管理相关接口")
public class SetmealController {
    @Autowired
    private SemealService semealService;
    @PostMapping
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
    public Result save(@RequestBody SetmealDTO setmealDTO){
        semealService.save(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    public Result getpage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult=semealService.getpage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @DeleteMapping
    @CacheEvict(cacheNames = "stemealCache",allEntries = true)
    public Result clearid(@RequestParam List<Long>ids){
        semealService.clearid(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getid(@PathVariable Long id){
        SetmealVO setmealVO=semealService.getid(id);
        return Result.success(setmealVO);
    }
    @PutMapping
    @CacheEvict(cacheNames = "stemealCache",allEntries = true)
    public Result update(@RequestBody SetmealDTO setmealDTO){
        semealService.update(setmealDTO);
        return Result.success();
    }
  @PostMapping("/status/{status}")
  @CacheEvict(cacheNames = "stemealCache",allEntries = true)
    public Result inster(@PathVariable Integer status,Long id){
        semealService.inster(status,id);
        return Result.success();
  }
}
